<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="呼叫类型" prop="callType">
        <el-select v-model="queryParams.callType" clearable placeholder="请选择呼叫类型">
			    <el-option label="呼入" value="1"></el-option>
			    <el-option label="呼出" value="2"></el-option>
			  </el-select>
      </el-form-item>
      <el-form-item label="号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="呼叫时间">
        <el-date-picker
		      v-model="queryParams.startTime"
		      type="date"
		      value-format="yyyy-MM-dd"
		      placeholder="选择开始日期">
		    </el-date-picker>
		    --
        <el-date-picker
		      v-model="queryParams.endTime"
		      type="date"
		      value-format="yyyy-MM-dd"
		      placeholder="选择结束日期">
		    </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%;"
    >
      <!-- <el-table-column label="主叫号码" align="center" prop="callaccept" :show-overflow-tooltip="true" /> -->
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.page - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="呼叫类型" align="center" prop="callintype" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.callintype == 'in'">呼入</span>
          <span v-if="scope.row.callintype == 'out'">呼出</span>
        </template>
      </el-table-column>
      <el-table-column label="主叫号码" align="center" prop="callphone" :show-overflow-tooltip="true" />
      <el-table-column label="被叫号码" align="center" prop="becalledphone" :show-overflow-tooltip="true" />
      <el-table-column label="呼叫时间" align="center" prop="createtime" :show-overflow-tooltip="true" />
      <el-table-column label="接听时间" align="center" prop="answeredtime" :show-overflow-tooltip="true" />
      <el-table-column label="挂机时间" align="center" prop="overtime" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="text" size="mini" icon="el-icon-microphone" @click="play(scope.row)">播放语音</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-bottom"
            @click="download(scope.row)"
          >下载</el-button>-->
          <!--<a :href="audiourl" download="下载">下载</a>-->
        </template>
      </el-table-column>
    </el-table>
		<pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.pageSize" @pagination="getList" />
    <!-- <div style="text-align: right;margin-top: 10px;">
			<el-button v-if="prevdisabled == true" type="primary" @click="prevclick">上一页</el-button>
			<el-button v-if="prevdisabled == false" type="primary" disabled>上一页</el-button>
			<el-button v-if="nextdisabled == true" type="primary" @click="nextclick">下一页</el-button>
			<el-button v-if="nextdisabled == false" type="primary" disabled>下一页</el-button>
    </div> -->
    <el-dialog
		  title="播放语音"
		  :visible.sync="dialogVisible"
		  width="30%" style="margin-top: 200px;">
		  <audio :src="audiourl" controls="controls" style="width: 100%;">
                  您的浏览器不支持 audio 标签。
     </audio>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="dialogVisible = false">取 消</el-button>
		  </span>
		</el-dialog>
  </div>
</template>

<script>
import { list } from "@/api/call/callInfo";
import { getIppbxConfig } from "@/api/call/ippbxServer";

export default {
  name: "Online",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 查询参数
      queryParams: {
				page: 1,
				pageSize: 10,
      },
      prevdisabled: false,
      nextdisabled: true,
      dialogVisible: false,
      audiourl: '',
    };
  },
  created() {
    this.getList();
  },
  methods: {
  	play(row){
  		this.dialogVisible = true;
  		getIppbxConfig().then(response=>{
        this.audiourl = row.recordfile.replace('127.0.0.1', response.data.ip)
  		});
  		
  	},
    prevclick() {
      if(this.queryParams.offset == 1){
      	this.prevdisabled = false;
      }else{
      	this.queryParams.offset -= 1;
      	this.nextdisabled = true;
      	this.getList();
      }
    },
    nextclick() {
      if(this.list.length < this.queryParams.limit){
      	this.nextdisabled = false;
      }else{
      	this.queryParams.offset += 1;
    		this.prevdisabled = true;
      	this.getList();
      }
    },
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.list = response.rows;
				this.total = response.total;
        this.loading = false;
        // if(this.queryParams.offset == 1){
        // 	this.prevdisabled = false;
        // }else if(this.list.length < this.queryParams.limit){
        // 	this.nextdisabled = false;
        // }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$confirm('是否确认强退名称为"' + row.userName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return forceLogout(row.tokenId);
        }).then(() => {
          this.getList();
          this.msgSuccess("强退成功");
        })
    }
  }
};
</script>

